//
//  loginRegisterViewController.m
//  百思不得姐os1
//
//  Created by kqy on 8/3/16.
//  Copyright © 2016 kqy. All rights reserved.
//

#import "loginRegisterViewController.h"
#import "kqyLoginButton.h"
@interface loginRegisterViewController ()

@end

@implementation loginRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kqyRandomColor;
    
    [self setBackGroundImg];
    [self setupBottomUI];
    [self setupTopUI];
    [self setupInputUI];
}
- (void) setBackGroundImg {
     UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:@"login_register_background"] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
//    self.view.backgroundColor = [UIColor colorWithPatternImage:image];
    
}
- (void) setupInputUI {
    UIImageView *middleImg = [[UIImageView alloc] init];
    middleImg.image = [UIImage imageNamed:@"login_rgister_textfield_bg"];
    [self.view addSubview:middleImg];
    middleImg.translatesAutoresizingMaskIntoConstraints = NO;
    
    // middle view constraint
    NSLayoutConstraint *middleLeftCon = [NSLayoutConstraint constraintWithItem:middleImg attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:50];
    NSLayoutConstraint *middleRightCon = [NSLayoutConstraint constraintWithItem:middleImg attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view  attribute:NSLayoutAttributeTrailing multiplier:1 constant:-50];
    NSLayoutConstraint *middleTopCon = [NSLayoutConstraint constraintWithItem:middleImg attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:120];
    [self.view addConstraints:[NSArray arrayWithObjects:middleLeftCon,middleRightCon,middleTopCon, nil]];
    
    UIView *inputView = [[UIView alloc] init];
//    UIView *inputView = [[UIView alloc] init];
//    UIView *inputView = [[UIView alloc] init];
//    UIView *inputView = [[UIView alloc] init];
    
    
}

- (void) setupTopUI {
    UIImageView *cancelImg = [[UIImageView alloc] init];
    [cancelImg setImage:[UIImage imageNamed:@"login_close_icon"]];
    [self.view addSubview:cancelImg];
    cancelImg.translatesAutoresizingMaskIntoConstraints = NO;
    
    UIButton *registBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [registBtn setTitle:@"register" forState:UIControlStateNormal ];
    [self.view addSubview:registBtn];
    registBtn.translatesAutoresizingMaskIntoConstraints = NO;
    // constraint
    NSLayoutConstraint *cancelTopCon = [NSLayoutConstraint constraintWithItem:cancelImg attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:50];
    NSLayoutConstraint *cancelLeftCon = [NSLayoutConstraint constraintWithItem:cancelImg attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:20];
    [self.view addConstraints:[NSArray arrayWithObjects:cancelTopCon,cancelLeftCon, nil]];
}
- (void) setupBottomUI {
//    kqyLoginButton *sinaShareBtn = [[kqyLoginButton alloc] initWithFrame:CGRectMake(100, 100, 100, 120)];
    kqyLoginButton *sinaShareBtn = [[kqyLoginButton alloc] init];
    [sinaShareBtn setTitle:@"新浪" forState:UIControlStateNormal];
    [sinaShareBtn setImage:[UIImage imageNamed:@"login_sina_icon"] forState:UIControlStateNormal];
    [sinaShareBtn setImage:[UIImage imageNamed:@"login_sina_icon_click"] forState:UIControlStateHighlighted];
    [self.view addSubview: sinaShareBtn];
    sinaShareBtn.translatesAutoresizingMaskIntoConstraints = NO;
    // 2 qq
    kqyLoginButton *qqShareBtn = [[kqyLoginButton alloc] init];
    [qqShareBtn setTitle:@"qq" forState:UIControlStateNormal];
    [qqShareBtn setImage:[UIImage imageNamed:@"login_QQ_icon"] forState:UIControlStateNormal];
    [qqShareBtn setImage:[UIImage imageNamed:@"login_QQ_icon_click"] forState:UIControlStateHighlighted];
    [self.view addSubview: qqShareBtn];
    qqShareBtn.translatesAutoresizingMaskIntoConstraints = NO;
    // 3
    kqyLoginButton *tencentShareBtn = [[kqyLoginButton alloc] init];
    [tencentShareBtn setTitle:@"tencent" forState:UIControlStateNormal];
    [tencentShareBtn setImage:[UIImage imageNamed:@"login_tecent_icon"] forState:UIControlStateNormal];
    [tencentShareBtn setImage:[UIImage imageNamed:@"login_tecent_icon_click"] forState:UIControlStateHighlighted];
    [self.view addSubview:tencentShareBtn];
    tencentShareBtn.translatesAutoresizingMaskIntoConstraints = NO;
    // 4
    UILabel *loginQuicklyLbl = [[UILabel alloc] init];
    loginQuicklyLbl.text = @"loginQuickly";
    [self.view addSubview:loginQuicklyLbl];
    loginQuicklyLbl.translatesAutoresizingMaskIntoConstraints = NO;
    // 5 ，6 left,right Line
    UIImageView *leftLineImage = [[UIImageView alloc] init];
    leftLineImage.image = [UIImage imageNamed:@"login_register_left_line"];
    [self.view addSubview:leftLineImage];
    UIImageView *rightLineImage = [[UIImageView alloc] init];
    rightLineImage.image = [UIImage imageNamed:@"login_register_right_line"];
    [self.view addSubview:rightLineImage];
    leftLineImage.translatesAutoresizingMaskIntoConstraints = NO;
    rightLineImage.translatesAutoresizingMaskIntoConstraints = NO;
    
    // 1 sina constraint
    NSLayoutConstraint *sinaLeftCon = [NSLayoutConstraint constraintWithItem:sinaShareBtn attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:10];
    NSLayoutConstraint *sinaBottomCon = [NSLayoutConstraint constraintWithItem:sinaShareBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:-10];
    NSLayoutConstraint *sinaHeight = [NSLayoutConstraint constraintWithItem:sinaShareBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:110];
    [self.view addConstraints:[NSArray arrayWithObjects:sinaLeftCon,sinaBottomCon,sinaHeight, nil]];
    // 2 qq constrtaint
    NSLayoutConstraint *qqLeftCon = [NSLayoutConstraint constraintWithItem:qqShareBtn attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:sinaShareBtn attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    NSLayoutConstraint *qqTopCon = [NSLayoutConstraint constraintWithItem:qqShareBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sinaShareBtn attribute:NSLayoutAttributeTop multiplier:1 constant:0];
    NSLayoutConstraint *qqBottomCon = [NSLayoutConstraint constraintWithItem:qqShareBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:sinaShareBtn attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    NSLayoutConstraint *qqWidthCon = [NSLayoutConstraint constraintWithItem:qqShareBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:sinaShareBtn attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
    [self.view addConstraints:[NSArray arrayWithObjects:qqLeftCon,qqBottomCon,qqTopCon,qqWidthCon, nil]];
    // 3 tencent
    NSLayoutConstraint *tencentLeftCon = [NSLayoutConstraint constraintWithItem:tencentShareBtn attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:qqShareBtn attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    NSLayoutConstraint *tencentTopCon = [NSLayoutConstraint constraintWithItem:tencentShareBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:qqShareBtn attribute:NSLayoutAttributeTop multiplier:1 constant:0];
    NSLayoutConstraint *tencentBottomCon = [NSLayoutConstraint constraintWithItem:tencentShareBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:qqShareBtn attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    NSLayoutConstraint *tencentRightCon = [NSLayoutConstraint constraintWithItem:tencentShareBtn attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0];
    NSLayoutConstraint *tencentWidthCon = [NSLayoutConstraint constraintWithItem:tencentShareBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:qqShareBtn attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
    [self.view addConstraints:[NSArray arrayWithObjects:tencentLeftCon,tencentTopCon,tencentBottomCon,tencentRightCon,tencentWidthCon, nil]];
    // 4
    NSLayoutConstraint *labelBottomCon = [NSLayoutConstraint constraintWithItem:loginQuicklyLbl attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:qqShareBtn attribute:NSLayoutAttributeTop multiplier:1 constant:-20];
    NSLayoutConstraint *labelCenterXCon = [NSLayoutConstraint constraintWithItem:loginQuicklyLbl attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [self.view addConstraints:[NSArray arrayWithObjects:labelBottomCon,labelCenterXCon, nil]];
    // 5
    NSLayoutConstraint *Line1WidthCon = [NSLayoutConstraint constraintWithItem:leftLineImage attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:120 ];
    NSLayoutConstraint *Line1HeightCon = [NSLayoutConstraint constraintWithItem:leftLineImage attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:1];
    NSLayoutConstraint *Line1RightCon = [NSLayoutConstraint constraintWithItem:leftLineImage attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:loginQuicklyLbl attribute:NSLayoutAttributeLeading multiplier:1 constant:-5];
    NSLayoutConstraint *Line1CenterYCon = [NSLayoutConstraint constraintWithItem:leftLineImage attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:loginQuicklyLbl attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [self.view addConstraints:[NSArray arrayWithObjects:Line1WidthCon,Line1HeightCon,Line1RightCon,Line1CenterYCon,nil]];
    // 6 right line constraint
    
    
}

- (void) setupMiddleUI {
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
